package main

import "fmt"

type Node struct {
	V    int
	Prev *Node
	Next *Node
}

func main() {
	var n, m, x int
	_, _ = fmt.Scan(&n, &m)

	data := make([][]int, m)
	for i := 0; i < m; i++ {
		_, _ = fmt.Scan(&x)
		data[i] = make([]int, x)
		for j := 0; j < x; j++ {
			_, _ = fmt.Scan(&data[i][j])
		}
	}

	f(data)
}

func f(data [][]int) {
	nm := make(map[int]*Node)
	for i := 0; i < len(data); i++ {
		if _, ok := nm[data[i][0]]; !ok {
			nm[data[i][0]] = &Node{
				V: data[i][0],
			}
		}
		for j := 1; j < len(data[i]); j++ {
			if _, ok := nm[data[i][j]]; !ok {
				nm[data[i][j]] = &Node{
					V: data[i][j],
				}
			}
			link(nm[data[i][j-1]], nm[data[i][j]])
		}
	}

	count := 1
	flag := make(map[int]struct{})
	queue := make([]int, 1)
	queue[0] = 0
	flag[0] = struct{}{}

	for len(queue) != 0 {
		n := len(queue)
		for i := 0; i < n; i++ {
			node := nm[queue[i]]
			prev := node.Prev
			for prev != nil {
				if _, ok := flag[prev.V]; !ok {
					flag[prev.V] = struct{}{}
					queue = append(queue, prev.V)
					count++
				}
				prev = prev.Prev
			}
			next := node.Next
			for next != nil {
				if _, ok := flag[next.V]; !ok {
					flag[next.V] = struct{}{}
					queue = append(queue, next.V)
					count++
				}
				next = next.Prev
			}
		}

		queue = queue[n:]
	}

	fmt.Println(count)
}

func link(n1, n2 *Node) {
	if n1.Next == nil {
		n1.Next = n2
	} else {
		n1.Next.Prev = n2
		n1.Next = n2
	}

	if n2.Prev == nil {
		n2.Prev = n1
	} else {
		n2.Prev.Next = n1
		n2.Prev = n1
	}
}
